package com.ctsi.commons.event;

import com.ctsi.commons.util.UtilObject;

import java.util.Collections;
import java.util.EventObject;
import java.util.Map;

/**
 * 事件数据包装
 * 
 * @author zhangjw
 * 
 */
public class BaseEvent extends EventObject {
	protected final String eventName;
	protected final  Map<String, ?> context;

	/**
	 * @param source 事件源
	 * @param name 事件id
	 * @param context 附加信息
	 */
	public BaseEvent(Object source, String name, Map<String, ?> context) {
		super(source);
		this.eventName = name;
		this.context = context;
	}

	/**
	 * @param source 事件源
	 * @param name 事件id
	 */
	public BaseEvent(Object source, String name) {
        this(source,   name,null);
	}

	/**
	 * 事件ID
	 * 
	 * @return
	 */
	public String getEventName() {
		return eventName;
	}

	/**
	 * 获取附加数据
	 * @return
	 */
	public Map<String, ?> getContext() {
		if (context != null) {
			return Collections.unmodifiableMap(context);
		} else {
			return Collections.emptyMap();
		}
	}
	@Override
	public String toString(){
		return UtilObject.toStr(this);
	}
}
